<template>
	<view>
		<view class="u-page">
			<view class="top-box">
				<!-- 背景图 -->
				<view class="top-color">
					<image src="../../static/index/banner.png" mode="widthFix" style="width: 100%;height: 100%;">
					</image>
				</view>
				<!-- 轮播图 -->
				<x-swiper :swiperList="swiperList"></x-swiper>
			</view>
			<view class="print bg-ffshow">
				<!-- 打印title -->
				<!-- 打印功能的板块显示 -->
				<x-banner :printList="printList" modebool='widthFix' @clickPrint="switchPrint">
					<x-title leftpx="40" title="打印功能" slot="title"></x-title>
				</x-banner>
			</view>
			<view class="x-banner">
				<x-title leftpx="40" title="更多功能" slot="title"></x-title>
				<u-cell-group :border="false">
					<u-cell-item title="订单取件码" :border-bottom="true" @click="orderCode">
						<image slot="icon" src="../../static/index/order@2x.png" mode=""
							style="width: 44rpx;height: 46rpx;margin: 0rpx 22rpx 0rpx 20rpx;">
						</image>
					</u-cell-item>
					<u-cell-item title="设备导航" @click="navaPnd">
						<image slot="icon" src="../../static/index/navigation@2x.png" mode=""
							style="width: 44rpx;height: 46rpx;margin: 0rpx 22rpx 0rpx 20rpx;">
						</image>
					</u-cell-item>
				</u-cell-group>
			</view>
		</view>
		<u-tabbar :list="list" :iconSize=40 :mid-button="true" :before-switch="beforeSwitch"></u-tabbar>
	</view>
</template>
<script>
	// noorder  获取订单号的接口是含有spu的 也就是说明 不能一开始就获取全局的订单号
	var QQMapWX = require('../../common/js/qqmap-wx-jssdk.min.js');
	var qqmapsdk;

	import {
		noorder
	} from "@/api/xcx/NewOrder.js"

	export default {
		data() {
			return {
				key: 'TXLBZ-FAOLW-XX6RP-RT7FK-XVUSZ-6BB2O',
				city: '河南省郑州市金水区健康路与优胜北路交叉口西南方向', //目标位置
				lat: 0, //维度
				lng: 0, //精度
				list: [],
				swiperList: [{
					ImageURL: '../../static/index/banner2.jpg'
				}],
				printList: [{
						// SPUId: 1000,//最原始的spu
						SPUId: 1014, //扫码的spu
						name: "文档上传打印",
						url: "../../static/index/file@2x.png"
						// url: "http://192.168.2.220:5000/Images/wechat/首页/file@2x.png"
					},
					{
						SPUId: 1005,
						name: "证卡打印",
						url: "../../static/index/idcard@2x.png"
						// url: "http://192.168.2.220:5000/Images/wechat/首页/idcard@2x.png"
					},
					{
						SPUId: 1005,
						name: "身份证打印",
						url: "../../static/index/id@2x.png"
						// url: "http://192.168.2.220:5000/Images/wechat/首页/id@2x.png" 
					},
					// {
					// 	SPUId: 1005,
					// 	name: "身份证打印",
					// 	url: "../../static/index/id@2x.png"
					// 	// url: "http://192.168.2.220:5000/Images/wechat/首页/id@2x.png" 
					// },
					{
						SPUId: 1008,
						name: "空白A4纸",
						// url: "../../static/index/a4@2x.png"原来的
						url: "../../static/index/a4@2x.png" //代替品
						// url: "http://192.168.2.220:5000/Images/wechat/首页/a4@2x.png"
					},
					{
						SPUId: 1007,
						name: "模板打印",
						url: "../../static/index/template@2x.png"
						// url: "http://192.168.2.220:5000/Images/wechat/首页/template@2x.png"
					},

					// 生活照打印和身份证打印换位置了

					{
						SPUId: 1003,
						name: "生活照打印",
						// url: "../../static/index/lifephoto@2x.png"
						url: "../../static/index/lifephoto@2x.png" //代替品
						// url: "http://192.168.2.220:5000/Images/wechat/首页/lifephoto@2x.png"
					},

					{
						SPUId: 1002,
						name: "证件照打印",
						url: "../../static/index/idphopo@2x.png"
						// url: "http://192.168.2.220:5000/Images/wechat/首页/idphopo@2x.png"
					},
					{
						SPUId: 7,
						name: "广告投放",
						url: "../../static/index/ad@2x.png"
						// url: "http://192.168.2.220:5000/Images/wechat/首页/ad@2x.png"
					},
				],

				messageSA4: {
					orderId: '',
					url: '../../indexPackages/A4/A4',
					title: 'A4空白纸',
					img: '../../static/wps@2x.png'
				}
			}
		},
		onLoad() {
			// 实例化API核心类
			qqmapsdk = new QQMapWX({
				key: 'TXLBZ-FAOLW-XX6RP-RT7FK-XVUSZ-6BB2O'
			});
			this.list = this.$store.state.list
			uni.checkSession({
				success: (res) => {
					console.log(res, 'checkSession')
					console.log("处于登录态");
				},
				fail: (res) => {
					uni.showModal({
						title: '登录已过期',
						content: '请重新去登录',
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: '../myUserLogo/myUserLogo'
								})
							}
						}
					})
					console.log("需要重新登录");
				}
			});
			// 获取token
		},
		onShow() {
			qqmapsdk.geocoder({
				//获取表单传入地址
				address: this.city, //地址参数，例：固定地址，address: '北京市海淀区彩和坊路海淀西大街74号'
				success: (res) => { //成功后的回调
					console.log(res);
					this.lat = res.result.location.lat; //维度
					this.lng = res.result.location.lng; //精度
					//根据地址解析在地图上标记解析地址位置 
				}
			});

		},
		methods: {
			//获取订单号
			orderId() {
				noorder([{
					"field": "SPUId",
					"value": "1014"
				}]).then(res => {
					uni.hideLoading()
					let orderid = res.data.orderId;
					uni.navigateTo({
						url: '../../indexPackages/uploadDocument-print/uploadDocument-print?orderid=' +
							orderid
					})
					console.log(res, 'res')
				})
			},
			// 获取token
			getInfoList() {
				getInfo().then(res => {
					console.log(res, '获取token')
				})
			},
			// 设备导航
			navaPnd() {
				uni.navigateTo({
					url: '../../indexPackages/NavigationPND/NavigationPND=' + this.lat + '&lng=' + this.lng
				})
			},
			orderCode() {
				uni.navigateTo({
					url: '../../indexPackages/orderCode-print/orderCode-print'
				})
			},
			beforeSwitch(index) {
				console.log(index);
				return true;
			},
			switchPrint(index) {
				uni.showLoading({
					title: '加载中...'
				})
				switch (index) {
					case 0:
						noorder([{
							"field": "SPUId",
							"value": "1014"
						}]).then(res => {
							uni.hideLoading()
							let orderid = res.data.orderId;
							uni.navigateTo({
								url: '../../indexPackages/uploadDocument-print/uploadDocument-print?orderid=' +
									orderid
							})
							console.log(res, 'res')
						})
						break;
					case 1:
						// 证卡打印
						noorder([{
							"field": "SPUId",
							"value": "1005"
						}]).then(res => {
							uni.hideLoading()
							let orderid = res.data.orderId;
							uni.navigateTo({
								url: '../../indexPackages/idCard-print/idCard-print?orderid=' +
									orderid
							})
							console.log(res, 'res')
						}).catch(error => {
							uni.hideLoading()
							uni.showToast({
								title: 'token失效',
								icon: 'none'
							})
						})
						break;
					case 2:
						// 身份证打印
						noorder([{
							"field": "SPUId",
							"value": "1005"
						}]).then(res => {
							uni.hideLoading()
							let orderid = res.data.orderId;
							uni.navigateTo({
								url: '../../indexPackages/idPhone-print/idPhone-print?orderid=' +
									orderid
							}).catch(error => {
								uni.hideLoading()
								uni.showToast({
									title: 'token失效',
									icon: 'none'
								})
							})
							console.log(res, 'res')
						})
						break;
					case 3:
						// 空白A4纸
						noorder([{
							"field": "SPUId",
							"value": "1008"
						}]).then(res => {
							uni.hideLoading()
							let orderid = res.data.orderId;
							this.messageSA4.orderId = orderid;
							console.log(this.messageSA4, 'this.messageSA4')
							uni.navigateTo({
								url: '../selectPrinter/selectPrinter?messageList=' + JSON.stringify(this
									.messageSA4)
							}).catch(error => {
								uni.hideLoading()
								uni.showToast({
									title: 'token失效',
									icon: 'none'
								})
							})
							console.log(res, 'res')
						})
						break;
					case 4:
						// 模板打印 
						noorder([{
							"field": "SPUId",
							"value": "1007"
						}]).then(res => {
							uni.hideLoading();
							let orderid = res.data.orderId;
							uni.navigateTo({
								url: '../selectPrinter/selectPrinter?orderid=' +
									orderid
							})
							console.log(res, 'res')
						})
						break;
					case 5:
						// 生活照打印
						uni.showToast({
							icon: 'none',
							title: '无法获取orderid'
						})
						// noorder([{
						// 	"field": "SPUId",
						// 	"value": "1003"
						// }]).then(res => {
						// 	uni.hideLoading()
						// 	let orderid = res.data.orderId;
						// 	uni.navigateTo({
						// 		url: ' ?orderid=' +
						// 			orderid
						// 	})
						// 	console.log(res, 'res')
						// })
						break;
					case 6:
						uni.showToast({
							icon: 'none',
							title: '无法获取orderid'
						})
						// 证件照打印
						// noorder([{
						// 	"field": "SPUId",
						// 	"value": "1002"
						// }]).then(res => {
						// 	uni.hideLoading()
						// 	let orderid = res.data.orderId;
						// 	uni.navigateTo({
						// 		url: ' ?orderid=' +
						// 			orderid
						// 	})
						// 	console.log(res, 'res')
						// })
						break;
					case 7:
						uni.hideLoading()
						uni.showToast({
							icon: 'none',
							title: '暂无开放'
						})
						console.log('广告投放');
				}
			}
		}
	}
</script>

<style lang="scss">
	.top-box {
		/* border: 1px solid red; */
		height: 324rpx;
		width: 750rpx;
		position: relative;
		margin-bottom: 30rpx;
	}
</style>
